// DialogOptionColor.cpp : implementation file
//

#include "stdafx.h"
#include "map863.h"
#include "DialogOptionColor.h"


// CDialogOptionColor dialog

IMPLEMENT_DYNAMIC(CDialogOptionColor, CDialog)

CDialogOptionColor::CDialogOptionColor(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogOptionColor::IDD, pParent)
{
//	for (int i=0;i<8;i++)
//		DisplayColors[i]=RGB(200,200,200);
}

CDialogOptionColor::~CDialogOptionColor()
{
}

void CDialogOptionColor::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO2, m_ComboBox);
	DDX_Control(pDX, IDC_FontInstance, m_FontInstance);
	DDX_Control(pDX, IDC_IMAGE, m_LineImage);
}


BEGIN_MESSAGE_MAP(CDialogOptionColor, CDialog)
	ON_BN_CLICKED(IDC_BUTTON2, &CDialogOptionColor::OnBnClickedButton2)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON1, &CDialogOptionColor::OnBnClickedButton1)
//	ON_CBN_SELENDCANCEL(IDC_COMBO2, &CDialogOptionColor::OnCbnSelendcancelCombo2)
	ON_CBN_SELCHANGE(IDC_COMBO2, &CDialogOptionColor::OnCbnSelchangeCombo2)
//	ON_EN_SETFOCUS(IDC_EDIT1, &CDialogOptionColor::OnEnSetfocusEdit1)
END_MESSAGE_MAP()


// CDialogOptionColor message handlers

BOOL CDialogOptionColor::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here

	m_ComboBox.AddString(_T("Background"));
	m_ComboBox.AddString(_T("Normal node"));
	m_ComboBox.AddString(_T("Rectangle edge of selected node"));
	m_ComboBox.AddString(_T("Highlight path"));
	m_ComboBox.AddString(_T("Normal path"));
	m_ComboBox.AddString(_T("Moving node"));	
	m_ComboBox.AddString(_T("Edge of selected area"));	
	m_ComboBox.AddString(_T("Selected path"));
	m_ComboBox.AddString(_T("Mesh"));
	m_ComboBox.AddString(_T("Text"));
	m_ComboBox.SetCurSel(0);

	OnCbnSelchangeCombo2();

	GetDlgItem(IDC_EDIT1)->SetWindowTextW(_T(""));
	GetDlgItem(IDC_EDIT1)->RedrawWindow(); 

	CFont tempFont;
	tempFont.CreateFontIndirect(&TextLogFont);
	m_FontInstance.SetFont(&tempFont);
	tempFont.DeleteObject();	

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogOptionColor::OnBnClickedButton2()
{
	// TODO: Add your control notification handler code here

	CColorDialog ColorDialog; 
	if (ColorDialog.DoModal()==IDOK)
	{
		int i=m_ComboBox.GetCurSel();
		LogPen[i].lopnColor=ColorDialog.GetColor();
		GetDlgItem(IDC_EDIT1)->RedrawWindow(); 
	}
}

HBRUSH CDialogOptionColor::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	COLORREF ColorSelected;
	// TODO:  Change any attributes of the DC here
	int tempCtrlID=pWnd->GetDlgCtrlID();
	if(tempCtrlID==IDC_EDIT1) 
	{ 
		//pDC->SetTextColor(RGB(255,0,0)); 
		ColorSelected=LogPen[m_ComboBox.GetCurSel()].lopnColor;

		pDC->SetBkColor(ColorSelected); 
		return CreateSolidBrush(ColorSelected);   
	} 
	else if(tempCtrlID==IDC_BUTTON2) 
	{ 
		//pDC->SetTextColor(RGB(255,0,0)); 
		ColorSelected=LogPen[m_ComboBox.GetCurSel()].lopnColor;
		pDC->SetBkColor(ColorSelected); 
		return CreateSolidBrush(ColorSelected);   
	} 

	// TODO:  Return a different brush if the default is not desired
	return hbr;
}

void CDialogOptionColor::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	CFontDialog FontDialog;
	CFont * pTextFont; 
	CFont NewTextFont;
	pTextFont=m_FontInstance.GetFont();
	pTextFont->GetLogFont(&TextLogFont);
	FontDialog.m_cf.lStructSize=sizeof(CHOOSEFONT);
	FontDialog.m_cf.lpLogFont=&TextLogFont;
	FontDialog.m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
	if (FontDialog.DoModal()==IDOK)
	{   
		FontDialog.GetCurrentFont(&TextLogFont);
		NewTextFont.CreateFontIndirect(&TextLogFont);
		m_FontInstance.SetFont(&NewTextFont);
	}
}

void CDialogOptionColor::OnCbnSelchangeCombo2()
{
	// TODO: Add your control notification handler code here
	
	GetDlgItem(IDC_EDIT1)->RedrawWindow(); 
	
	int i=m_ComboBox.GetCurSel();
	CPen pen1;
	pen1.CreatePenIndirect(&LogPen[i]);
	CDC * pDC;
	pDC=GetDC();
	CRect rect;
//	m_LineImage.Invalidate();
	//RedrawWindow();
	m_LineImage.GetWindowRect(&rect);
	ScreenToClient(rect);	
	CBrush Brush(RGB(255, 255, 255));
	pDC->FillRect(&rect,&Brush );
	pDC->SelectObject(&pen1);
	pDC->MoveTo(rect.left+1, rect.top+rect.Height()/2);
	pDC->LineTo(rect.right-1, rect.top+rect.Height()/2);
	//UpdateWindow() ;
}


void CDialogOptionColor::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class

//	CDialog::OnCancel();
}

void CDialogOptionColor::OnOK()
{
	// TODO: Add your specialized code here and/or call the base class

//	CDialog::OnOK();
}

